Customer = function(){};
Customer.addClassification = function(id,name){
    if(Customer.findClassification(id)){
        alert('Desculpe, essa classificação já está associada a esse cliente.');
    } else {
        var classifications = document.getElementById("classification_ids");
        if(classifications.value == ""){
           classifications.value = id; 
        } else {
            classifications.value = classifications.value + "," +id;
        }
                
        classifications = document.getElementById("classifications");
        var html = classifications.innerHTML;
        html += "<li id='classifications_li_"+id+"'>"+name+" <a href=\"javascript:Customer.removeClassification('"+id+"')\"><img src='/images/icons/remove.gif' border=\"0\" /></a></li>";
        classifications.innerHTML = html;
    }
};

Customer.loadClassification = function(id,name){
    var classifications = document.getElementById("classifications");
    var html = classifications.innerHTML;
    html += "<li id='classifications_li_"+id+"'>"+name+" <a href=\"javascript:Customer.removeClassification('"+id+"')\"><img src='/images/icons/remove.gif' border=\"0\" /></a></li>";
    classifications.innerHTML = html;
};

Customer.removeClassification = function(id){
    var classifications = document.getElementById("classification_ids");
    var classifications_ids = classifications.value.split(",");
    var ids = "";
    for(i=0;i<classifications_ids.length;i++){
        if(classifications_ids[i] != id){
            if(ids.length == 0){
                ids = classifications_ids[i];
            } else {
                ids += ","+classifications_ids[i];
            }
        }
    }
    
    classifications.value = ids;
    
    classifications = document.getElementById("classifications");
    var classificationLI = document.getElementById("classifications_li_"+id);
    classifications.removeChild(classificationLI);
    
};

Customer.findClassification = function(id){
    var classifications = document.getElementById("classification_ids").value.split(",");
    for(i=0;i<classifications.length;i++){
        if(classifications[i] == id){
            i = classifications.length;
            return true;
        }
    }
    return false;
};
